#ifndef __WIDGET_H
#define __WIDGET_H

#include <common/types.h>
#include <common/graphicscontext.h>
#include <driver/keyboard.h>
class Widget : public KeyboardEventHandler
{
private:
    
protected:
    Widget* parent;
    int32_t x;
    int32_t y;
    int32_t w;
    int32_t h;

    uint8_t r;
    uint8_t g;
    uint8_t b;

    bool focusable;
    
public:

    virtual void GetFocus(Widget* widget);
    //relative position to absolute position
    virtual void ModelToScreen(int32_t &x, int32_t &y);
    virtual bool ContainsCoordinate(int32_t x, int32_t y);

    virtual void Draw(GraphicsContext* gc);
    virtual void OnMouseDwon(int32_t x, int32_t y, uint8_t button);
    virtual void OnMouseUp(int32_t x, int32_t y, uint8_t button);
    virtual void OnMouseMove(int32_t oldX, int32_t oldY, int32_t newX, int32_t newY);

    virtual void OnKeyDown(char);
    virtual void OnKeyUp(char);



    Widget(Widget* parent, int32_t x, int32_t y, int32_t w, int32_t h,
            int32_t r, int32_t g, int32_t b);
    ~Widget();
};


class CompositeWidget: public Widget
{
private:
    
protected:
    Widget* children[100];
    int numChildren;
    Widget* focussedChild;
public:

    virtual void GetFocus(Widget* widget);
    virtual void AddChild(Widget* Widget);


    virtual void Draw(GraphicsContext* gc);
    virtual void OnMouseDwon(int32_t x, int32_t y, uint8_t button);
    virtual void OnMouseUp(int32_t x, int32_t y, uint8_t button);
    virtual void OnMouseMove(int32_t oldX, int32_t oldY, int32_t newX, int32_t newY);

    virtual void OnKeyDown(char);
    virtual void OnKeyUp(char);



    CompositeWidget(Widget* parent, int32_t x, int32_t y, int32_t w, int32_t h,
            int32_t r, int32_t g, int32_t b);
    ~CompositeWidget();
};




#endif